import request from '@/utils/request.js'

// 分页查询待入库订单列表
export const getStockInListService = (params) => {
    return request.get('/inventory/stockIn/list', { params })
}

// 执行入库操作
export const stockInService = (data) => {
    return request.post('/inventory/stockIn', {
        orderId: parseInt(data.orderId),           // 订单ID
        orderNo: data.orderNo,                     // 订单编号
        remark: data.remark,                       // 备注
        details: data.details.map(item => ({
            productId: parseInt(item.productId),    // 商品ID
            productName: item.productName,          // 商品名称
            quantity: item.quantity,                // 数量
            price: item.price,                     // 单价
            location: item.location                // 存放位置
        }))
    })
}

// 获取出库列表
export function getStockOutListService(params) {
    return request({
        url: '/inventory/stockOut/list',
        method: 'get',
        params
    })
}

// 获取库存详情
export function getStockDetailService(id) {
    return request({
        url: `/inventory/detail/${id}`,
        method: 'get'
    })
}

// 执行出库操作
export function stockOutService(data) {
    return request({
        url: '/inventory/stockOut',
        method: 'post',
        data
    })
}

// 分页查询库存列表
export const getInventoryListService = (params) => {
    return request.get('/inventory/list', { params })
}

// 修改库存
export const updateInventoryService = (data) => {
    return request.put('/inventory', data)
}

// 分页查询出库单列表
export function getOutboundListService(params) {
    return request({
        url: '/inventory/outbound/list',
        method: 'get',
        params
    })
}

// 获取出库单详情
export function getOutboundDetailService(orderId) {
    return request({
        url: `/inventory/outbound/detail/${orderId}`,
        method: 'get'
    })
}

// 新增出库单
export function addOutboundService(data) {
    return request({
        url: '/inventory/outbound/add',
        method: 'post',
        data
    })
}

// 审核出库
export function approveOutboundService(data) {
    return request({
        url: '/inventory/outbound/approve',
        method: 'post',
        data
    })
}

// 删除出库单
export function deleteOutboundService(orderId) {
    return request({
        url: `/inventory/outbound/delete/${orderId}`,
        method: 'delete'
    })
}